--------------------------------------------------------------------------------
-- help.lua
--   smartcard development help toolset
--
-- y.volta ET gmail.com
-- 2011/05/29 17:58:52 
--------------------------------------------------------------------------------

help = {}         -- create the help table

local s_help=[[
 Smartcard Specification Help System
  - help.list()       show available topics
  - help.ATR          ATR table, refer: 7816-3_2006_3rd
]];

setmetatable(help, 
{__tostring = function () return s_help; end }
)

-- sub_packages
local scard_svc = {
    atr = "./iso-iec/hlp_atr.lua",
    pps = "./iso-iec/hlp_pps.lua",
    --t0 = "hlp_t0.lua",
    t1 = "./iso-iec/hlp_t1.lua",
    sw = "./iso-iec/hlp_sw.lua",
    rs = "./iso-iec/hlp_rs.lua",
    ins = "./iso-iec/hlp_ins.lua"
}

-- helper function for init
function init_help (ns)
    for n,v in pairs(ns) do
       if _G[n] ~= nil then
           error("name clash: " .. n .. " is already defined")
       end
       _G[n] = dofile (v);
    end
end

function show_bits (t)
  tt = {};
  
  for k, v in pairs(t) do 
      if v then tt[k] = 1;
      else tt[k] = 0;
      end    
  end
  
  --for k, v in pairs(tt) do    print(k, v) end
  print(table.concat(tt, " "))
  
end

-- ISO7816, contact interface
function help.contact ()
  s_contact = [[
- C1: supply power input (VCC, see 5.2.1). 
- C2: reset signal input (RST, see 5.2.2). 
- C3: clock signal input (CLK, see 5.2.3). 
- C5: ground (GND, reference voltage). 
- C6: standard or proprietary use (SPU, see 5.2.4). 
- C7: input/output for serial data (I/O, see 5.2.5).   
  ]]
  
  print (s_contact);
end

-- init help package.
init_help (scard_svc)

----------------------------------------------------- end of script -----------
